package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	"time"
)

type MainController struct {
	beego.Controller
}

func (c *MainController) Get() {
	c.TplName = "index.html"
}

func (c *MainController) M_Get() {
	c.TplName = "m_index.html"
}

func (this *MainController) Prepare() {
	path := this.Ctx.Request.URL.Path
	fmt.Printf("path %+v\n", path)

	t, ok := access_t[this.Ctx.Request.RemoteAddr]
	if !ok {
		access_t[this.Ctx.Request.RemoteAddr] = time.Now()
	} else {
		if time.Now().Sub(t) < time.Second*5 {
			this.Data["json"] = struct {
				Hola        string `json:"西班牙"`
				Hello       string `json:"英语"`
				Bonjour     string `json:"法语"`
				Cigo        string `json:"意大利语"`
				Japanese    string `json:"日语"`
				NorthKorean string `json:"韩语"`
				Message     string `json:"message"`
			}{
				Hola:        "hola",
				Hello:       "hello",
				Bonjour:     "bonjour",
				Cigo:        "cigo",
				Japanese:    "こんにちは",
				NorthKorean: "안녕하세요",
				Message:     "可能访问得太频繁了... 等等再点击鼠标把",
			}

			this.ServeJSON(true)
			return
		} else {
			access_t[this.Ctx.Request.RemoteAddr] = time.Now()
		}
	}

}
